#! /bin/bash


DT=`date -d '0 days ago' "+%Y-%m-%d"`

if [[ $1 == "" ]];then
   TD_DATE=`date -d '1 days ago' "+%Y-%m-%d"`
else
   TD_DATE=$1
fi

echo '========================================'
echo '==============开始增量导入==============='
echo '========================================'


export LANG=zh_CN.UTF-8
HIVE_HOME=/usr/bin/hive


${HIVE_HOME} -S -e "


set hive.exec.dynamic.partition.mode=nonstrict;
insert overwrite table db_dwd.dim_class_studying_student_count partition(dt)
select * from db_ods.class_studying_student_count where class_id is not null  and studying_date is not null and studying_date='${DT}';


insert overwrite table db_dwd.dim_course_table_upload_detail
select * from db_ods.course_table_upload_detail where class_date is not null  and class_id is not null ;



set hive.exec.dynamic.partition.mode=nonstrict;
insert overwrite table db_dwd.facts_student_leave_apply partition (dt)
select * from db_ods.student_leave_apply where begin_time is not null  and class_id is not null and end_time is not null and date_format(create_time,'%Y-%m-%d')='${DT}';


insert overwrite table db_dwd.dim_tbh_class_time_table
select * from db_ods.tbh_class_time_table where morning_begin_time is not null  and class_id is not null ;



set hive.exec.dynamic.partition.mode=nonstrict;
insert overwrite table db_dwd.facts_tbh_student_signin_record partition (dt)
select * from db_ods.tbh_student_signin_record where signin_date is not null  and class_id is not null and id is not null and signin_date='${DT}' ;

"